from flask import Flask, request, Response, jsonify
import sys, json

app = Flask(__name__)

@app.route("/", methods=["GET", "POST"])
def index():
    # 返回python字典可以自动转化为json字符串
    info = {
        "username": "Will",
        "password": "123456",
        "telphone": ["13177233893", "41929023234"]
    }
    # print(request.data)
    # print(request.json["username"])
    # sys.stdout.write(request.form)
    # 自动将Python字典对象转化为json字符串
    # return info
    # 使用Response手动设置
    # return Response(json.dumps(info), mimetype="application/json")
    # 直接返回一个json字符串，会被当成html内容解析
    # return json.dumps(info)
    # return "<h1>Hello World</h1>"
    return jsonify(info)


if __name__ == "__main__":
    app.run(debug=True, port=80)
